package com.mvc.argumentResolver;

import java.lang.reflect.Parameter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mvc.annotation.ArgResover;
import com.mvc.annotation.RequestParam;

/**
 * Parameter 获取参数名,需要-parameters 否则只能获取到arg0,arg1,arg2
 * @author ZGame
 *
 */
@ArgResover(value = "String")
public class StringResolver implements ArgResolverInterface {

	@Override
	public Object argumentResolver(HttpServletRequest request, HttpServletResponse response, Parameter parameter) {
		String name = parameter.getName();
		if (parameter.isAnnotationPresent(RequestParam.class)) {
			RequestParam param = parameter.getAnnotation(RequestParam.class);
			if (!param.value().isEmpty()) {
				name = param.value();
			}
		}
		return request.getParameter(name);
	}
}
